// src/App.vue
<template>
  <div id="app">
    <el-container>
      <el-header class="header">
        <div class="logo">HRM人力资源管理系统</div>
        <div class="user-info">
          <el-dropdown>
            <span class="el-dropdown-link">
              <el-avatar :size="40" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <span style="margin-left: 10px;">管理员</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="goToPersonalCenter">个人中心</el-dropdown-item>
                <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>

      <el-container>
        <el-aside width="220px" class="sidebar">
          <el-menu
              router
              :default-active="activeMenu"
              class="menu"
              background-color="#f5f7fa"
              active-text-color="#409EFF"
          >
            <el-menu-item index="/dashboard">
              <i class="el-icon-s-data"></i>
              <span>控制面板</span>
            </el-menu-item>

            <el-sub-menu index="recruitment">
              <template #title>
                <i class="el-icon-s-claim"></i>
                <span>人才招聘</span>
              </template>
              <el-menu-item index="/recruitment/pending">待面试</el-menu-item>
              <el-menu-item index="/recruitment/employed">已录用</el-menu-item>
              <el-menu-item index="/recruitment/onboarded">已入职</el-menu-item>
              <el-menu-item index="/recruitment/rejected">已淘汰</el-menu-item>
            </el-sub-menu>

            <el-sub-menu index="personnel">
              <template #title>
                <i class="el-icon-s-custom"></i>
                <span>人事管理</span>
              </template>
              <el-menu-item index="/personnel/onboarding">入职管理</el-menu-item>
              <el-menu-item index="/personnel/transfer">调动管理</el-menu-item>
              <el-menu-item index="/personnel/leave">离职管理</el-menu-item>
            </el-sub-menu>

            <el-menu-item index="/organization">
              <i class="el-icon-s-management"></i>
              <span>组织管理</span>
            </el-menu-item>

            <el-menu-item index="/permission">
              <i class="el-icon-s-check"></i>
              <span>权限管理</span>
            </el-menu-item>

            <el-menu-item index="/positions">
              <i class="el-icon-s-flag"></i>
              <span>职位设置</span>
            </el-menu-item>

            <el-menu-item index="/statistics">
              <i class="el-icon-s-marketing"></i>
              <span>数据统计</span>
            </el-menu-item>

            <el-menu-item index="/logs">
              <i class="el-icon-s-order"></i>
              <span>操作日志</span>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <el-main class="main-content">
          <router-view v-slot="{ Component }">
            <transition name="fade" mode="out-in">
              <component :is="Component" />
            </transition>
          </router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';

export default {
  setup() {
    const route = useRoute();
    const router = useRouter();

    const activeMenu = computed(() => route.path);

    const goToPersonalCenter = () => {
      router.push('/personal-center');
    };

    const logout = () => {
      console.log('用户退出登录');
      router.push('/login');
    };

    return {
      activeMenu,
      goToPersonalCenter,
      logout
    };
  }
};
</script>

<style scoped>
#app {
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', Arial, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #409EFF;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 25px;
  height: 60px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logo {
  font-size: 20px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  color: white;
  cursor: pointer;
}

.sidebar {
  background-color: #f5f7fa;
  border-right: 1px solid #e6e6e6;
  overflow: hidden;
}

.menu {
  border-right: none;
  height: 100%;
}

.main-content {
  padding: 20px;
  background-color: #f0f2f5;
  overflow: auto;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>